package com.yksj.healthtalk.ui.server;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.TextView;

import com.yksj.healthtalk.adapter.ServerShopExpandListAdapter;
import com.yksj.healthtalk.adapter.ServerShopExpandListAdapter.ExpandGridListAdapter;
import com.yksj.healthtalk.comm.BaseFragmentActivity;
import com.yksj.healthtalk.comm.LodingFragmentDialog;
import com.yksj.healthtalk.entity.ShopEntityClassify;
import com.yksj.healthtalk.net.http.HttpRestClient;
import com.yksj.healthtalk.net.http.ObjectHttpResponseHandler;
import com.yksj.healthtalk.ui.R;
/**
 * 自选商店
 * @author Administrator
 *
 */
public class ServerCenterFreeShopActivity extends BaseFragmentActivity implements OnClickListener,AdapterView.OnItemClickListener{
	private ExpandableListView mListView;
	private ServerShopExpandListAdapter mAdapter = null;
	
	
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.server_center_free_shop_layout);
		initView();
		initData();
	}
	
	private void initView() {
		Button titleLeftBtn = (Button)findViewById(R.id.title_back);
		TextView titleTextV = (TextView)findViewById(R.id.title_lable);
		Button titleRightBtn2 = (Button)findViewById(R.id.title_right2);
		titleLeftBtn.setOnClickListener(this);
		titleLeftBtn.setBackgroundResource(R.drawable.title_back);
		titleTextV.setText("自选商品");
		titleRightBtn2.setVisibility(View.VISIBLE);
		titleRightBtn2.setOnClickListener(this);
		titleRightBtn2.setBackgroundResource(R.drawable.shopping_trolley);
		mListView = (ExpandableListView)findViewById(R.id.expandalistview);
		mListView.setGroupIndicator(null);
		mListView.setDescendantFocusability(ExpandableListView.FOCUS_AFTER_DESCENDANTS);
	}

    private void initData() {
    	
    	HttpRestClient.doHttpGetFreeShopData("1",new ObjectHttpResponseHandler() {
			private LodingFragmentDialog showLodingDialog;
			@Override
			public Object onParseResponse(String cotent) {
				return ShopEntityClassify.parseJsonToInfoRead(cotent);
			}
			public void onSuccess(int statusCode, Object response) {
				if(response == null)return;
				List<ShopEntityClassify> map = (List)response;
				
				
			};
			@Override
			public void onStart() {
				super.onStart();
				showLodingDialog = LodingFragmentDialog.showLodingDialog(getSupportFragmentManager(), "请稍后...");
			}
			@Override
			public void onFinish() {
				super.onFinish();
				showLodingDialog.dismissAllowingStateLoss();
			}
		});
    }
    
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_back:
			onBackPressed();
			break;
		case R.id.title_right2:
			Intent intent =new Intent(this,ServerCenterFreeShopCarActivity.class);
			startActivity(intent);
			break;
		}
	}
	
	

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		ExpandGridListAdapter adapter = (ExpandGridListAdapter)parent.getAdapter();
		ShopEntityClassify classify = adapter.getItem(position);
		Intent intent=new Intent(ServerCenterFreeShopActivity.this,ServerCenterShopList.class);
		intent.putExtra("entity", classify);
		startActivity(intent);
	}
}
